<template>
	<view class="container">
		<view class="left-bottom-sign"></view>
		<view class="back-btn yticon icon-zuojiantou-up" @click="navBack"></view>
		<view class="right-top-sign"></view>
		<!-- 设置白色背景防止软键盘把下部绝对定位元素顶上来盖住输入框等 -->
		<view class="wrapper">
			<view class="input-content">
				<!-- <view class="input-item">
					<text class="tit">用户名</text>
					<input type="text" v-model="username" placeholder="请输入用户名" maxlength="11"/>
				</view> -->
				<view class="input-item">
					<text class="tit">新密码</text>
					<input type="text" v-model="password" placeholder="8-18位不含特殊字符的数字、字母组合" placeholder-class="input-empty" maxlength="20"
					 password @confirm="toLogin" />
				</view>
				<view class="input-item">
					<text class="tit">确认密码</text>
					<input type="text" v-model="twopassword" placeholder="请确认您的新密码" placeholder-class="input-empty" maxlength="20"
					 password @confirm="toLogin" />
				</view>
				<view class="input-item">
					<text class="tit">手机号</text>
					<input type="text" v-model="telephone" placeholder="请输入您的手机号" maxlength="11"/>
				</view>
				<view class="input-item">
					<!-- <text class="tit">手机号</text> -->
					<input type="text" v-model="authCode" placeholder="请输入验证码" maxlength="6"/>
				</view>
				    <button class="confirm-btn" @click="getAuthCode" :disabled="countdown > 0">
				      {{ countdown > 0 ? `重新获取(${countdown}s)` : '获取验证码' }}
				    </button>
					<button class="confirm-btn" @click="toUpdate" >确认修改</button>
			</view>
			<!-- <view class="empty">
				<image src="/static/qrcode_for_macrozheng_258.jpg" mode="aspectFit"></image>
				<view class="empty-tips">
					扫描上方二维码<view class="navigator">关注公众号</view>，
				</view>
				<view class="empty-tips">
					回复<view class="navigator">会员</view>获取体验账号。
				</view>
			</view> -->
		</view>
	</view>
</template>

<script>
	import {
		memberUpdatePassword,memberGetAuthod
	} from '@/api/member.js';
	export default {
		data() {
			return {
				 countdown: 0,
				 
			}
			
		},
		onLoad() {
		},
		methods: {
			navBack() {
				uni.navigateBack();
			},
			async toUpdate() {
				
				if (this.password==this.twopassword) {
					memberUpdatePassword({
						telephone: this.telephone,
						password: this.password,
						authCode: this.authCode
					}).then(response=>{
								  if (!response.data) {
								    uni.showToast({
								      title: '修改成功',
								      icon: 'success',
								      duration: 1000 // 设置显示时间为1000毫秒，确保显示时间足够长
								    });
								    
								    setTimeout(() => {
								      uni.navigateBack();
								    }, 1000); // 设置延迟时间为100毫秒
								  } else {
								    uni.showToast({
								      title: '修改失败',
								      icon: 'none',
								    });
								  }
								  
							  }).catch(() => {
						
					});
					
				}else {
					uni.showToast({
					  title: '密码不一致！请重新输入',
					  icon: 'none',
					});
					// this.password='';
					// this.twopassword='';
					// data() {password : '',
					// twopassword : ''}
				}
				
			},
			async getAuthCode() {
			      if (this.countdown > 0) return;
				          if (this.telephone!=null) {
				          	memberGetAuthod({
								telephone: this.telephone,
				          	}).then(response=>{
								
				          								  if (!response.data.success) {
				          								    this.startCountdown();
				          								    uni.showToast({
				          								      title: '验证码已发送'+response.data,
				          								      icon: 'success',
				          								    });
															console.log(response.data)
				          								  } else {
				          								    uni.showToast({
				          								      title: '获取验证码失败',
				          								      icon: 'none',
				          								    });
				          								  }
				          								  
				          	}). catch(()=> {
				          	
				          	uni.showToast({
				          	  title: '获取验证码失败',
				          	  icon: 'none',
				          	});});
				          }else{
							  uni.showToast({
							    title: '获取验证码失败',
							    icon: 'none',
							  });
						  }

				         
				        
				 //  memberGetAuthod({
					//   telephone : this.telephone,
					//   }).then(response=>{
					// 	  this.startCountdown();
					// 	  uni.showToast({
					// 	    title: '验证码已发送',
					// 	    icon: 'success',
					// 	  });
					//   }).catch(
					//   uni.showToast({
			  //         title: '获取验证码失败',
			  //         icon: 'none',
			  //       })
					// );
				    
			    },
			    startCountdown() {
			      this.countdown = 60;
			      const interval = setInterval(() => {
			        if (this.countdown > 0) {
			          this.countdown--;
			        } else {
			          clearInterval(interval);
			        }
			      }, 1000);
			    },
			  },
		}

	
</script>

<style lang='scss'>
	page {
		background: #fff;
	}
	
	.empty {
		position: fixed;
		left: 0;
		top: 0;
		width: 100%;
		height: 100vh;
		padding-bottom: 100upx;
		display: flex;
		justify-content: center;
		flex-direction: column;
		align-items: center;
		background: #fff;
	
		image {
			width: 420upx;
			height: 420upx;
			margin-bottom: 30upx;
		}
		.empty-tips {
			display: flex;
			font-size: $font-sm+16upx;
			color: $font-color-disabled;
		
			.navigator {
				color: $uni-color-primary;
				margin-left: 0upx;
			}
		}
	}

	.container {
		padding-top: 115px;
		position: relative;
		width: 100vw;
		height: 100vh;
		overflow: hidden;
		background: #fff;
	}

	.wrapper {
		position: relative;
		z-index: 90;
		background: #fff;
		padding-bottom: 40upx;
	}

	.back-btn {
		position: absolute;
		left: 40upx;
		z-index: 9999;
		padding-top: var(--status-bar-height);
		top: 40upx;
		font-size: 40upx;
		color: $font-color-dark;
	}

	.left-top-sign {
		font-size: 120upx;
		color: $page-color-base;
		position: relative;
		left: -16upx;
	}

	.right-top-sign {
		position: absolute;
		top: 80upx;
		right: -30upx;
		z-index: 95;

		&:before,
		&:after {
			display: block;
			content: "";
			width: 400upx;
			height: 80upx;
			background: #b4f3e2;
		}

		&:before {
			transform: rotate(50deg);
			border-radius: 0 50px 0 0;
		}

		&:after {
			position: absolute;
			right: -198upx;
			top: 0;
			transform: rotate(-50deg);
			border-radius: 50px 0 0 0;
			/* background: pink; */
		}
	}

	.left-bottom-sign {
		position: absolute;
		left: -270upx;
		bottom: -320upx;
		border: 100upx solid #d0d1fd;
		border-radius: 50%;
		padding: 180upx;
	}
	.input-content {
		padding: 0 60upx;
	}
	.confirm-btn {
		width: 630upx;
		height: 76upx;
		line-height: 76upx;
		border-radius: 50px;
		margin-top: 70upx;
		background: $uni-color-primary;
		color: #fff;
		font-size: $font-lg;
	
	 		&:after {
			border-radius: 100px;
		}
	}
	.input-item {
		display: flex;
		flex-direction: column;
		align-items: flex-start;
		justify-content: center;
		padding: 0 30upx;
		background: $page-color-light;
		height: 120upx;
		border-radius: 4px;
		margin-bottom: 50upx;
	
		&:last-child {
			margin-bottom: 0;
		}
	
		.tit {
			height: 50upx;
			line-height: 56upx;
			font-size: $font-sm+2upx;
			color: $font-color-base;
		}
	
		input {
			height: 60upx;
			font-size: $font-base + 2upx;
			color: $font-color-dark;
			width: 100%;
		}
	}
</style>
